package com.bawei.lib_image

import android.graphics.Typeface
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.databinding.BindingAdapter

/**
 *作者：lxy
 *功能:
 *时间：2025/5/26
 */
object ImageBindingAdapter {
    @JvmStatic
    @BindingAdapter("avatarUrl")
    fun avatarUrl(imageView: ImageView, url: String) {
        GlideApp.with(imageView.context)
            .load(url)
            .placeholder(R.mipmap.icon_default_avatar)
            .error(R.mipmap.icon_default_avatar)
            .into(imageView)
    }

    @JvmStatic
    @BindingAdapter("normalImage")
    fun normalImage(imageView: ImageView, url: String?) {
        if (url.isNullOrEmpty() && imageView.visibility != View.VISIBLE)
            return
        GlideApp
            .with(imageView.context)
            .load(if (url.isNullOrEmpty()) "" else url)
            // .placeholder(imageView.drawable)
            .into(imageView)
    }

    @JvmStatic
    @BindingAdapter("toolImage")
    fun normalImage(imageView: ImageView, source: Any?) {

        GlideApp
            .with(imageView.context)
            .load(source)
            .into(imageView)
    }


    @JvmStatic
    @BindingAdapter("textBold")
    fun textBold(textView: TextView, boolean: Boolean) {
        textView.typeface = if (boolean) Typeface.DEFAULT_BOLD else Typeface.DEFAULT
    }
}